/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cassys.ejb.sessionbean;

import cassys.dataaccess.AssessmentDAO;
import cassys.dataaccess.DAOException;
import cassys.dataaccess.DAOFactory;
import cassys.datatransferobjects.AssessmentDTO;
import java.util.ArrayList;
import javax.ejb.EJB;
import javax.ejb.Stateless;

/**
 *
 * @author Priyanka
 */
@Stateless(mappedName = "AssessmentBean")
public class AssessmentBean implements AssessmentBeanRemote {

    public AssessmentDAO dao = null;

    public void ejbCreate() {
        dao = DAOFactory.getInstance().getAssessmentDAO();
    }

    @Override
    public void insertAssessment(AssessmentDTO dto) throws DAOException {
        dao.insertAssessment(dto);
    }

    @Override
    public void deleteAssessment(AssessmentDTO dto) throws DAOException {
        dao.deleteAssessment(dto);
    }

    @Override
    public ArrayList<AssessmentDTO> getAllAssessmentByModule(String moduleCode) throws DAOException {

        ArrayList<AssessmentDTO> modules = null;
        AssessmentDTO[] modArray = null;

        modArray = dao.getAllAssessmentByModule(moduleCode);

        if (modArray.length > 0) {
            modules = new ArrayList<AssessmentDTO>(modArray.length);
            for (int i = 0; i < modArray.length; i++) {
                modules.add(i, modArray[i]);
            }
        }

        return modules;

    }

    @Override
    public ArrayList<AssessmentDTO> findAllAssessments() throws DAOException {
        return dao.findAllAssessment();
    }

    @Override
    public AssessmentDTO findAssessment(String assessmentId) throws DAOException {
        return dao.findAssessment(assessmentId);
    }

    @Override
    public ArrayList<AssessmentDTO> findAllAssessmentsById(String assessmentId) throws DAOException {
        return dao.findAllAssessmentById(assessmentId);
    }
}
